﻿using System.Web.Security;
using NTQOnlineExam.Services.Infrastructure;
using NTQOnlineExam.Services.Models;
using NTQOnlineExam.Services.ReportService.Account;

namespace NTQOnlineExam.Services.ReportService.Basket
{
    public class BasketReportService : IBasketReportService
    {
        private readonly ICommandExecutor _commandExecutor;
        private readonly IAccountReportService _accountReportService;
        public BasketReportService(ICommandExecutor commandExecutor, IAccountReportService accountReportService)
        {
            _commandExecutor = commandExecutor;
            _accountReportService = accountReportService;
        }

        public BasketDTO GetShoppingBasketByUserName(string userName)
        {
            return _commandExecutor.Execute(new GetUserBasketDTODbCommand(userName));
        }

        public BasketDTO GetCurrentBasket()
        {
            var currentUser = _accountReportService.GetCurrentUser();
            if (currentUser == null) return null;
            return GetShoppingBasketByUserName(currentUser.UserName);
        }
    }
}
